package com.weikuang.fareast.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.trello.rxlifecycle2.android.ActivityEvent;
import com.weikuang.fareast.R;
import com.weikuang.fareast.adapter.CheckQueryDetailsAdapter;
import com.weikuang.fareast.bean.CheckBean;
import com.weikuang.fareast.bean.CheckDetailBean;
import com.weikuang.fareast.bean.QueryNewBean;
import com.weikuang.fareast.http.MainHttp;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.dlc.commonlibrary.okgo.rx.OkObserver;
import cn.dlc.commonlibrary.ui.widget.TitleBar;
import cn.dlc.commonlibrary.utils.ToastUtil;
import cn.dlc.commonlibrary.utils.rv_tool.RecyclerViewUtil;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class CheckQueryDetailsActivity extends BaseActivity {
    @BindView(R.id.mTitleBar)
    TitleBar mTitleBar;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    String order_id = "";
    CheckQueryDetailsAdapter mCheckAdapter;
    List<CheckBean> datasList = new ArrayList<>();


    QueryNewBean.DataBean data;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_check_query_details;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        mTitleBar.leftExit(this);
        InitRecyclerView();
        data = (QueryNewBean.DataBean)getIntent().getSerializableExtra("data");
        if (data != null){
            order_id = data.id;
            checkDetail(data.id);
        }

    }


    private void InitRecyclerView() {
        mCheckAdapter = new CheckQueryDetailsAdapter();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        RecyclerViewUtil.setDefaultDivider(mRecyclerView, linearLayoutManager);
        mRecyclerView.setAdapter(mCheckAdapter);

    }
    private void checkDetail(String orderId) {
        MainHttp.get().checkDetail(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new OkObserver<CheckDetailBean>() {
                    @Override
                    public void onSuccess(CheckDetailBean hotelBean) {
                        showOneToast(hotelBean.msg);
                        datasList.clear();
                        for (int i = 0; i < hotelBean.data.size(); i++) {
                            CheckBean bean1 = new CheckBean(hotelBean.data.get(i).hotel, hotelBean.data.get(i).office, hotelBean.data.get(i).title,
                                    hotelBean.data.get(i).goods_id, Integer.valueOf(hotelBean.data.get(i).check), Integer.valueOf(hotelBean.data.get(i).bad)
                                    ,Integer.valueOf(hotelBean.data.get(i).back),String.valueOf(hotelBean.data.get(i).ctime), hotelBean.data.get(i).amount,false,Integer.parseInt(data.status));
                            datasList.add(bean1);
                        }
                        mCheckAdapter.setNewData(datasList);
                    }

                    @Override
                    public void onFailure(String message, Throwable tr) {
                        ToastUtil.show(getActivity(), message);
                    }
                });
    }






}
